package jk.spider.core.task.dispatch;

import jk.spider.core.SpiderController;
import jk.spider.core.task.WorkerTask;
import jk.spider.core.task.threading.WorkerThreadPool;

import org.apache.log4j.Logger;

public class DispatchExtractTasks extends DispatcherTask {
	protected static final Logger log = Logger.getLogger(DispatchExtractTasks.class);
	protected WorkerThreadPool extracts;
	protected SpiderController controller;
	protected int count = 0;
	
	public DispatchExtractTasks(SpiderController controller, WorkerThreadPool extracts) {
		super(controller, extracts);
		this.controller = controller;
		this.extracts = extracts;
	}
	
	public int getType() {
		return WorkerTask.WORKERTASK_EXTRACTTASK;
	}

	public void prepare() { }

	public void execute() {
		log.info("Extract task dispatcher running ...");
		while(running) {
			try {
				extracts.assign(controller.getContent().getExtractTask());
			} catch (InterruptedException e) {
				log.warn("DispatchExtractTasks InterruptedException -> ", e);
				running = false;
			}
		}
		log.info("Extract task dispatcher dying ...");
	}

}